﻿using Microsoft.WindowsAzure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BackupManager.Configuration
{
    public class ConfigManager
    {
        private ConfigManager()
        { 
        
        }

        private static ConfigManager _Instance;
        public static ConfigManager Instance
        {
            get 
            {
                if (_Instance == null)
                {
                    lock (typeof(ConfigManager))
                    {
                        if (_Instance == null)
                        {
                            _Instance = new ConfigManager();
                            _Instance.Load();
                        }                    
                    }
                }
                return _Instance;
            }
        }

        public void Load()
        {
            StorageConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
            EncryptionKey = CloudConfigurationManager.GetSetting("EncryptionKey");
            AuthenticationUserName = CloudConfigurationManager.GetSetting("AuthenticationUserName");
            AuthenticationPassword = CloudConfigurationManager.GetSetting("AuthenticationPassword");
            DefaultSqlBackupContainerName = CloudConfigurationManager.GetSetting("DefaultSqlBackupContainerName");
            int maximumNumberOfBackupCopies = 0;
            if (!int.TryParse(CloudConfigurationManager.GetSetting("MaximumNumberOfBackupCopies"), out maximumNumberOfBackupCopies))
            {
                maximumNumberOfBackupCopies = 7;
            }
            MaximumNumberOfBackupCopies = maximumNumberOfBackupCopies;
        }

        public string CertificateServerName { get; set; }
        public string StorageConnectionString { get; set; }
        public string EncryptionKey { get; set; }
        public string AuthenticationUserName { get; set; }
        public string AuthenticationPassword { get; set; }
        public string DefaultSqlBackupContainerName { get; set; }

        public int MaximumNumberOfBackupCopies { get; set; }
    }
}